export default class Input {
    private _codeState: Map<number, boolean> = new Map();

    private static _instance: Input = new Input();
    public static getInstance(): Input {
        return this._instance;
    }

    private constructor() {
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
    }

    private onKeyDown(event) {
        this._codeState.set(event.keyCode, true);
    }

    private onKeyUp(event) {
        this._codeState.set(event.keyCode, false);
    }

    public isKeyPressed(keyCode: cc.macro.KEY) {
        return this._codeState.get(keyCode);
    }
}
